package com.army.stock.service.impl;

import com.army.stock.dao.ArmyDepartmentDao;
import com.army.stock.domain.ArmyDepartment;
import com.army.stock.service.ArmyDepartmentService;
import com.javalife.common.domain.page.PaginatedArrayList;

import java.util.List;
import java.util.Map;

/**
 * Created by zhangyong on 14/12/29.
 */
public class ArmyDepartmentServiceImpl implements ArmyDepartmentService {

    private ArmyDepartmentDao armyDepartmentDao;

    public void setArmyDepartmentDao(ArmyDepartmentDao armyDepartmentDao) {
        this.armyDepartmentDao = armyDepartmentDao;
    }

    public PaginatedArrayList getArmyDepartmentPageInfo(int currentPage, int pageSize, Map<String, Object> map) {
        int startNum = (currentPage - 1) * pageSize;
        map.put("start", startNum);
        map.put("pageSize", pageSize);
        Integer count = armyDepartmentDao.getCountArmyDepartments(map);
        List<ArmyDepartment> Departments = armyDepartmentDao.getArmyDepartments(map);
        PaginatedArrayList<ArmyDepartment> paginatedArrayList = new PaginatedArrayList<ArmyDepartment>(currentPage, pageSize);
        paginatedArrayList.setTotalItem(count);
        paginatedArrayList.addAll(Departments);
        return paginatedArrayList;
    }

    public void addArmyDepartment(ArmyDepartment armyDepartment) {
        armyDepartmentDao.insertArmyDepartment(armyDepartment);
    }

    public ArmyDepartment getArmyDepartmentById(Long id) {
        return armyDepartmentDao.getArmyDepartmentById(id);
    }

    public void updateArmyDepartment(ArmyDepartment armyDepartment) {
        armyDepartmentDao.updateArmyDepartment(armyDepartment);
    }

    public Integer delArmyDepartment(Long id) {
        return armyDepartmentDao.delArmyDepartment(id);
    }

    public List<ArmyDepartment> getAllArmyDepartments() {
        List<ArmyDepartment> dataList = armyDepartmentDao.getArmyDepartments(null);
        return dataList;
    }

    public ArmyDepartment getArmyDepartmentByIdFromCache(Long DepartmentId) {
        ArmyDepartment armyDepartment  = armyDepartmentDao.getArmyDepartmentById(DepartmentId);
        return armyDepartment;
    }

    public ArmyDepartment getArmyDepartmentByParam(ArmyDepartment param){
        return armyDepartmentDao.getArmyDepartmentByParam(param);
    }

}
